/*
 * SocketMonitor.h
 *
 *  Created on: 2012-12-27
 *      Author: yangentao@gmail.com
 */
#pragma once;
#include "BaseSocket.h"
#include "../Thread.h"

namespace yet {

//will close socket when SocketMonitor destructor
//call monitor after socket created
class SocketMonitor {
public:
	SocketMonitor();
	virtual ~SocketMonitor();
public:
	void monitor(SOCKET s, boost::function<void (SOCKET s, SocketError e)> closeCallback);
	void cancel();
private:
	int onRun(void* arg);
private:
	BaseSocket sock;
	boost::function<void (SOCKET s, SocketError e)> OnClose;
	Thread thread;
	bool isCancel;
};

} /* namespace yet */
